package com.ssy.lingxi.product.repository;

import com.ssy.lingxi.product.entity.CommodityPriceRecord;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.time.LocalDate;
import java.util.List;

/**
 * 商品记录持久化层
 * @author jw.chen
 * @version 2.0.0
 * @date 2021/10/19
 */
public interface CommodityPriceRecordRepository extends JpaRepository<CommodityPriceRecord,Long>, JpaSpecificationExecutor<CommodityPriceRecord> {

    List<CommodityPriceRecord> findByCommoditySkuIdAndDateBetweenOrderByDateAsc(Long commoditySkuId, LocalDate startDate, LocalDate endDate);

    @Query("select min(price) from CommodityPriceRecord where commoditySkuId = ?1")
    Double findMinPriceByCommoditySkuId(Long commoditySkuId);

    List<CommodityPriceRecord> findByCommoditySkuIdInAndDate(List<Long> commoditySkuIdList, LocalDate date);
}
